package show.me.the.money.util.exp.standard;

import java.util.List;

import show.me.the.money.util.context.Context;
import show.me.the.money.util.exp.ExpRunner;
import show.me.the.money.util.exp.ExpSymbols;
import show.me.the.money.util.exp.Expression;

@SuppressWarnings("unchecked")
public class OR extends Expression {
	public OR() {
		symbol = ExpSymbols.OR;
	}

	public String run(List lsExp, Context ctx) {
		boolean result = false;
		try {
			int size = lsExp.size();
			for (int i = 1; i < size; i++) {
				List la = (List)lsExp.get(i);
				boolean b = (Boolean)(ExpRunner.run(la, ctx));
				if (b) {
					result = b;
					break;
				}
			}
		} 
		catch (Exception e) {
			logger.fatal("run JSONException:", e);
		}
		return String.valueOf(result);
	}

	public String toString(List lsExp, Context ctx) {
		return "(" + super.toString(lsExp, ctx) + ")";
	}
}
